package org.apache.flink.runtime.metrics.scope;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.runtime.metrics.groups.ResourceProviderMetricGroup;

/** The scope format for the {@link org.apache.flink.runtime.metrics.groups.ConsumerMetricGroup}. */
public class ResourceProviderConsumerScopeFormat extends ScopeFormat {

    public ResourceProviderConsumerScopeFormat(String format, ResoruceProviderScopeFormat parentFormat) {
        super(
                format,
                parentFormat,
                new String[] {SCOPE_HOST, SCOPE_TASKMANAGER_ID, SCOPE_JOB_ID, SCOPE_JOB_NAME});
    }

    public String[] formatScope(ResourceProviderMetricGroup parent, ConsumerID consumerId, String consumerName) {
        final String[] template = copyTemplate();
        final String[] values = {
            parent.hostname(), parent.taskManagerId(), valueOrNull(consumerId), valueOrNull(consumerName)
        };
        return bindVariables(template, values);
    }
}
